var fileUpload = new Class({
    Implements : [ Events, Options ],
    name : 'fileUpload',
    options : {
        pNode : null,
        name : null,
        rule : null,
        css : null,
        isMulti: 'true',
        maxSize:0 ,//默认不限制上传个数
        size:null, //input file 的size属性
        keepfile:'false'//选择完后是否保留原状态
    },
    initialize : function(options) {
        this.htmlOptions(options);
    },
    uploadButton : null,
    uploadContent : null,
    uploadTempContent : null,
    uploadLoading : null,
    selectFile : null,
    uploadForm : null,
    iframeKey : 'FileUploadCommitIframe',
    wrap:null,
    innerWrap:null,
    parent:null,
    box:null,
    initParam : function(item, parent) {
        this.parent = parent;
        return ;
        /*this.wrap = new Element('div', {
            'name':this.options.name,
            'class':'uploadGroup formselect-list swordform_item_oprate',
            'widgetGetValue':'true',
            'rule':this.options.rule,
            'widget':true,
            'keepfile':this.options.keepfile,
            'styles':{'float':'left'
            }}).inject(this.options.pNode);
        this.wrap.store("parent", parent);
        this.innerWrap = new Element('div', {
            'class':'formselect-list-inner'
        }).inject(this.wrap);
        this.parseFileRow("init");
        sword_convertHTML(this.box, item);
        if(item.get("size")) {
            this.options.size = item.get("size");
            this.box.set("size", this.options.size);
        }
        return this;*/
    },
    reset:function() {
        this.innerWrap.getElements("input[type='file']").each(function(el) {
            el.set("value", "");
        });
    },
    disable:function(wrapEl){
    	wrapEl.getElements("input").set('disabled', true);
    },
    enable:function(wrapEl){
    	wrapEl.getElements("input").set('disabled', false);
    },
    resetElStatus:function(el) {
        this.wrap = el.store("parent", this.parent);
        this.innerWrap = this.wrap.getFirst();
        this.innerWrap.getElements("input[type='button']").each(function(el) {
            if(el.get('value') == "增加") {
                this.box = el.addEvent('click', function() {
                    this.parseFileRow("add");
                    this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
                }.bind(this));
            } else if(el.get('value') == "取消") {
                el.addEvent("click", function(e) {
                    new Event(e).target.getParent("div").destroy();
                    this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
                }.bind(this));
            }
        }.bind(this));
    },
    getValue:function() {
        var re = "";
        this.wrap.getElements("input[type='file']").each(function(el) {
            re = ((re == "") ? re : (re + ",")) + el.get("value");
        });
        return re;
    },
    //生成文件上传或者展现的一行
    parseFileRow:function(bz) {
        var row = new Element('div', { 'class':'formselect-list-item'}).inject(this.innerWrap);
        var input = new Element('input', {'type':'file','name':this.options.name}).inject(row);
         new Element('input', {'type':'button','value':'清空','events':{
                'click':function(e) {
                    var input = new Event(e).target.getPrevious("input");
                    var el = input.clone(false);
                    input.getParent().insertBefore(el, input);
                    el.value = "";//firefox 必须手动清空input的值
                    input.destroy();
                }.bind(this)
            }}).inject(row);
        this.box = input;
        if(this.options.size != null)
            this.box.set("size", this.options.size);
        var loadedDiv = new Element("span", {'class':'fileuploadloaded'}).inject(row);
        if(bz == "init" && this.options.isMulti == "true") {
            var btn = new Element('input', {'type':'button','value':'增加','events':{
                'click':function() {
                    if(this.options.maxSize > 0 && this.innerWrap.getChildren().length >= this.options.maxSize) {
                        alert("您最多只能上传" + this.options.maxSize + "个文件。");
                        return;
                    }
                    this.parseFileRow("add");
                    this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
                }.bind(this)
            }}).inject(row);
            
            
        } else if(bz == "add") {
            var btn = new Element('input', {'type':'button','value':'取消','events':{
                'click':function(e) {
                    new Event(e).target.getParent("div").destroy();
                    this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
                }.bind(this)
            }}).inject(row);
        }

    },
    //初始化文件列表
    initData : function() {
        //如果列表展现不是由程序员来定义,组件负责初始化数据，否则由页面容器来初始化数据
    },
    loading : function() {
        var p = this.selectFile.getPosition();
        if(this.uploadContent.getStyle('display') == 'none') {
            this.uploadContent.setStyles({'display' : '','height' : '35px'});
            this.uploadLoading.setStyles({'display' : '','left' : p.x + 10,'top' : p.y + this.selectFile.getHeight(),'width' : '300px','height' : '35px'});
        } else {
            var p1 = this.uploadContent.getPosition();
            var w = this.uploadContent.getWidth();
            var h = this.uploadContent.getHeight();
            this.uploadLoading.setStyles({'display' : '','left' : p1.x,'top' : p1.y,'width' : w + 5,'height' : h + 35});
        }
    },
    endLoding : function() {
        this.uploadLoading.setStyle('display', 'none');
    },
    //转换单位
    setupSize:function(size) {
        var sizename = new Array("B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
        var times = 0;
        while(size >= 1024) {
            size = size / 1024;
            times++;
        }
        if(times > 0) {
            return size.toFixed(2) + sizename[times];
        } else {
            return size + sizename[times];
        }
    }
    ,initEvent:function(){
    	var addEl=this.innerWrap.getElement("input[type='button'][value='增加']");
        if(addEl){addEl.addEvent('click',function() {
        	if(this.options.maxSize > 0 && this.innerWrap.getChildren().length >= this.options.maxSize) {
                alert("您最多只能上传" + this.options.maxSize + "个文件。");
                return;
            }
            this.parseFileRow("add");
            this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
       }.bind(this));}
        this.innerWrap.getElement("input[type='button'][value='清空']").addEvent('click',function(e) {
        	var input = new Event(e).target.getPrevious("input");
            var el = input.clone(false);
            input.getParent().insertBefore(el, input);
            el.value = "";//firefox 必须手动清空input的值
            input.destroy();
       }.bind(this));
   }
});
var FormBlockArea = new Class({
    Implements:[Events,Options],
    name:'formblock',
    options:{
        pNode:null,
        caption:null,
        isHide:null,
        name:null,
        isShow:null
    },
    initialize:function(options) {
        this.setOptions(options);
    },
    legendFx:null,//隐藏的特效
    fieldset:null,
    legend:null,
    initParam:function() {
        var fb = new Element("div", {'class':'swordform_block','name':this.options.name}).inject(this.options.pNode);
        var fbt = new Element("div", {'class':'swordform_block_top'}).inject(fb);
        fbt.set('html', "<div class='l'></div><div class='r'></div>");
        var fbc = new Element("div", {'class':'swordform_block_center'}).inject(fb);
        var fbc_l = new Element("div", {'class':'ll'}).inject(fbc);
        var fbc_r = new Element("div", {'class':'rr'}).inject(fbc_l);
        var fbb = new Element("div", {'class':'swordform_block_bottom'}).inject(fb);
        fbb.set('html', "<div class='l'></div><div class='r'></div>");
        if(this.options.isShow == "false") {
            fb.setStyle("display", "none");
        }
        return fbc_r;
    }
});

var SwordPanel = new Class({
    Implements:[Events,Options],
    name:'SwordPanel',
    options:{
        pNode:null,
        caption:null
    },
    tc:null,
    initialize:function(options) {
        this.setOptions(options);
    },
    initParam:function() {
        var panel = new Element('div', {'class':'swordform-panel-box'}).inject(this.options.pNode);
        var tl = new Element('div', {'class':'swordform-panel-tl'}).inject(panel);
        var tr = new Element('div', {'class':'swordform-panel-tr'}).inject(panel);
        this.tc = new Element('div', {'class':'swordform-panel-title'}).appendText(this.options.caption||'').inject(panel);
        return this;
    },
    updateTitle:function(t) {
        this.tc.set('text', t);
    }
});
var Textarea = new Class({
    Implements:[Events,Options],
    name:"textarea",
    options:{
        css:null,
        scroll:false,
        pNode:null,
        name:null,
        rule:null,
        bizValidate:'false',
        biztid :null,
        bizctrl:null,
        msg:null,
        defValue:null,
        edit:null,
        maxLength:null,
        x:null,
        y:null
        ,autoHeight:'false'
        ,maxHeight:300
    },
    defWidth:500,//默认宽度
    defHeight:120,//默认高度
    box:null,
    countSpan:null,
    parent:null,
    initialize:function(options) {
        this.htmlOptions(options);
    },
    initParam:function(parent) {
        this.parent = parent;
        /*this.box = new Element('textarea', {
            'class':'swordform_item_oprate swordform_item_textarea',
            'name':this.options.name,
            'rule':this.options.rule,
            'bizValidate':this.options.bizValidate,
            'biztid':this.options.biztid,
            'bizctrl':this.options.bizctrl,
            'msg':this.options.msg,
            'widget':"true"
        }).inject(this.options.pNode);*/
        /*if((this.options.rule || "").indexOf("must") > -1 && parent.options.requiredSign == "field") {
            new Element("span", {'styles':{'color':'red','float':'left'},'html':"*"}).inject(this.options.pNode);
        }
        if($chk(this.options.css) || $chk(this.options.x) || $chk(this.options.y)) {
        	var styles="";
        	if($chk(this.options.css)){
        			styles = styles + this.options.css + ";";
        	}
        	if($chk(this.options.x)) {
        		styles = styles + "width:" +  Sword.utils.valPx(this.options.x) + ";";
        	}
        	if($chk(this.options.y)){
        		styles = styles + "height:" + Sword.utils.valPx(this.options.y) + ";";
        	}
            this.box.set('style', styles);
        } */
        if(this.options.edit == "false") {
            this.box.set('disabled', true);
        }
        /*if(parent.isVal() && $defined(this.options.rule)) {
           Sword.utils.createElAfter(this.options.pNode);
        }
        if($defined(this.options.maxLength)) {
            var div = new Element("div", {'styles':{'clear':'both','color':'#333','float':'left','width':this.box.getStyle("width"),'margin-left':'0','text-align':'left'},'text':"您还可以输入"}).inject(this.options.pNode);
            this.countSpan = new Element("span", {'text':this.options.maxLength}).inject(div);
            new Element('span', {'styles':{'font-size':'12px','font-weight':'lighter'},'text':"字"}).inject(div);
            this.box.addEvent('blur', this.maxLengthCount.bind(this));
            this.box.addEvent('change', this.maxLengthCount.bind(this));
            this.box.addEvent("keyup", this.maxLengthCount.bind(this));
        }*/
        if($defined(this.options.defValue)) {
            this.initData(this.options.defValue);
        }
        //if(this.options.autoHeight=='true')Sword.utils.autoTextarea(this.box,this.options.maxHeight);
        return this.box;
    },
    setAutoHeight:function(){
        Sword.utils.setAutoTextArea(this.box,this.options.maxHeight);
    },
    maxLengthCount:function(e) {
        if(this.getValue().length > this.options.maxLength / 1) {
            if(e) {
                try {
                    with(window.event || e) {
                        cancelBubble = true;
                        keyCode = 0;
                        returnValue = false;
                    }
                } catch(ex) {
                }
            }
            this.box.set("value", this.getValue().substring(0, this.options.maxLength / 1));
        }
        var len = this.options.maxLength / 1 - this.getValue().length;
        this.countSpan.set("text", (len >= 0) ? len : 0);
        if(len == 0)this.countSpan.getParent().setStyle('color', 'red');
        else this.countSpan.getParent().setStyle('color', '#333');
    },
    leftUTFString:function(str, len) {
        if(this.getStringUTFLength(str) <= len) {
            return str;
        }
        var value = str.substring(0, len);
        while(this.getStringUTFLength(value) > len) {
            value = value.substring(0, value.length - 1);
        }
        return value;
    },
    getStringUTFLength:function(str) {
    	var v = str.replace(/[\u4e00-\u9fa5]/g, "  ");
        return v.length;
    },
    initData:function(value) {
        if(!$defined(value))value = "";
        value = value.replace(/&apos;/g, "'");
        this.box.set('value', value);
        if($defined(this.options.maxLength))this.maxLengthCount();
        return this.box;
    },
    getValue:function() {
        return this.box.get("value");
    },
    reset:function() {
        this.initData("");
        this.parent.Vobj.clearElTip(this.box);
    },
    focus:function() {
        this.box.focus();
    }
    ,initEvent:function() {
        this.box.addEvent('blur', this.maxLengthCount.bind(this));
        this.box.addEvent('change', this.maxLengthCount.bind(this));
        this.box.addEvent("keyup", this.maxLengthCount.bind(this));
    }
});
var SwordGroupFields = new Class({
    Implements:[Events,Options],
    name:'groupfields',
    $family: {name: 'groupfields'},
    options:{
        tag:null,
        pNode:null,
        data:null,
        dataname:null,
        validate:null,
        name:null,
        rule:null,
        type:null,
        colWidth:null,
        col:1,
        onClickBefore:null,
        onClickAfter:null,
        sbmitcontent:null,
        msg:null,
        defValue:null,
        disable:'false'
    },
    initialize:function(options) {
        this.htmlOptions(options);
    },
    wrap:null,
    innerWrap:null,
    parent:null,
    initParam:function(itemD, parent) {
        this.parent = parent;
        this.options.validate = parent.Vobj;
        this.options.tag = itemD.get("type");
        this.options.opts = itemD.getChildren(">div");
        /*this.wrap = new Element('div', {
            'name':this.options.name,
            'class':'formselect-list swordform_item_oprate',
            'rule':this.options.rule,
            'widget':'true',
            'msg':this.options.msg,
            'widgetGetValue':'true',
            'ruleType':this.options.type + 'Group'
            }).inject(this.options.pNode);
        this.innerWrap = new Element('div', {
            'defValue':this.options.defValue,
            'class':'formselect-list-inner'
        }).inject(this.wrap);*/
       /* if((this.options.rule || "").indexOf("must") > -1 && parent.options.requiredSign == "field") {
            new Element("span", {'styles':{'color':'red','float':'left'},'html':"*"}).inject(this.options.pNode);
        }*/
       
        if(this.options.opts.length > 0)this.initOptionsData(this.options.opts);
        /*if(parent.isVal() && $defined(this.options.rule)) {
            Sword.utils.createElAfter(this.options.pNode);
        }*/
        if(this.options.disable == 'true')this.disable();
        return this;
    },
    initalizeData:null,
    initalized :false,
    initData:function(d,el) {
        /*todo 此处代码先注释,为统一使用dataName初始化数据
         * if((Browser.Engine.trident4 ) && arguments.length == 1) {
            this.parent.lazyInitData.set(this.options.name, d);
            return;
        }
        var dv = this.innerWrap.get("defValue");
        if(d == "" && $defined(dv))d = dv;
        if(d / 1 == 1 || d / 1 == 0)d = d + ",1";
        d = d.toHash();
        if($type(d) == "hash") {
            this.initalizeData = d;
            this.reset();
            d.each(function(v, k) {
                if(v / 1 == 1) {
                    var inp = this.innerWrap.getElement("input[value='" + k + "']");
                    if(inp) {
                        inp.set("checked", true);
                        inp.getParent().addClass('formselect-selected');
                    }
                }
            }, this);
        }
        this.parent.lazyInitData.erase(this.options.name);
        this.initalizeData = null;*/

    	if($type(d)=="string"){
    		this.reset();
    		d.split(",").each(function(v, k) {
    			var inp = this.innerWrap.getElement("input[value='" + v + "']");
                if(inp) {
                    inp.set("checked", true);
                    inp.getParent().addClass('formselect-selected');
                }
           }, this);
    	}else{
	    	if(d.initpage!=true){
	    		this.initOptionsData(d.data);
	    	}
    	}
    },
    initOptionsData:function(data) {
    	this.clearOptions();
    	if($chk(data)){
        	if($type(data.data)=="array"){data=data.data;}
	        data.each(function(item, idx) {
	            var row = new Element('div', {'class':'formselect-list-item'}).inject(this.innerWrap);
	            if($defined(this.options.colWidth)) row.setStyles({'width':this.options.colWidth});
	            var code,caption;
	            if($type(item) == 'element') {
	                code = item.get('code');
	                caption = item.get('caption');
	            } else {
	                code = item['code'];
	                caption = item['caption'];
	            }
	            row.set({'code':code,'caption':caption});
	            var input = new Element('input', {'type':this.options.type,'rule':this.options.rule,'ruleType':this.options.type + 'Group','name':this.options.name}).inject(row);
                input.setStyle('cursor','pointer').set('value', code);
	            /*if(this.options.tag != 'multiselect') {
	                var input = new Element('input', {'type':this.options.type,'rule':this.options.rule,'ruleType':this.options.type + 'Group','name':this.options.name}).inject(row);
	                input.setStyle('cursor','pointer');
	                row.addEvent('click', function(e) {
	                	var tar = $(new Event(e).target);
	                    if (tar.get("tag") == "div")return;
	                    var code="",caption="";
	                    if (tar.get("type") == "radio") {
	                        var oldeEl = this.innerWrap.getElement("div.formselect-selected");
	                        if (oldeEl) {
	                        	code= oldeEl.get("code");
	                            caption = oldeEl.get("caption");
	                        }
	                    }else{
	                    	var oldeEl = this.innerWrap.getElements("div.formselect-selected");
	                        if (oldeEl.length>0) {
	                        	oldeEl.each(function(item){
	                        		code= code+(item.get("code")+",");
	                                caption =caption+(item.get("caption")+",");
	                        	});
	                        	code=code.substring(0,code.length-1);
	                        	caption=caption.substring(0,caption.length-1);
	                        }
	                    }
	                    if ($defined(this.options.onClickBefore)) {
	                        this.getFunc(this.options.onClickBefore)[0](code, caption,tar);
	                    }
	                    var tarParent = tar.getParent();
	                    var inputEl=tarParent.getElement("input");
	                    if (inputEl.get("type") == "radio") {
	                        this.innerWrap.getElements("div.formselect-list-item").each(function(row) {
	                        	if (row.getElement("input")){
	                            	if(!(row.getElement("input").get("disabled"))){
	                            		row.getElement("input").set("checked", false);
	                            		row.removeClass("formselect-selected");
	                            	}
	                            }else{
	                            	row.removeClass("formselect-selected");
	                            }
	                        });
	                        if (!$chk(inputEl.get('disabled'))){
	                        	tarParent.addClass('formselect-selected');
	                        	inputEl.set("checked", true);
	                        }
	                    } else {
	                    	if (tarParent.hasClass("formselect-selected")) {
	                            if (!$chk(inputEl.get('disabled')))inputEl.set("checked", false);
	                            tarParent.removeClass('formselect-selected');
	                        }
	                        else {
	                            if (!$chk(inputEl.get('disabled')))inputEl.set("checked", true);
	                            tarParent.addClass('formselect-selected');
	                        }
	                    }
	                    if ($defined(this.options.onClickAfter)) {
	                        this.getFunc(this.options.onClickAfter)[0](tarParent.get("code"), tarParent.get("caption"),tarParent);
	                    }
	                }.bind(this));
	                input.set('value', code);
	            } else {
	                row.addEvent('click', function(e) {
	                    if(this.options.disable == "true")return;
	                    if($defined(this.options.onClickBefore))
	                        this.getFunc(this.options.onClickBefore)[0](code, caption,row);
	                    row.getParent().getElements("div").each(function(itemDivItem) {
	                        itemDivItem.removeClass('formselect-selected');
	                    }, this);
	                    row.addClass('formselect-selected');
	                    if($defined(this.options.onClickAfter))
	                        this.getFunc(this.options.onClickAfter)[0](code, caption,row);
	                }.bind(this));
	
	            }*/
	            new Element("span", {'text':caption, 'title':caption}).inject(row);
	            row.addEvents({
	        		'mouseenter':function(e){if(!row.getElement("input").get("disabled"))row.addClass("formselect-hover");},
	        		'mouseleave':function(e){if(!row.getElement("input").get("disabled"))row.removeClass("formselect-hover");}
	        	});
	            this.parent.reSizeRow(this.options.pNode.getParents("div.swordform_row_div")[0]);
	        }, this);
    	}
        if(this.initalizeData != null) {
            this.initData(this.initalizeData, "ie6");
        }
        if(this.options.defValue != null) {
            this.initData(this.options.defValue);
        }
        return this;
    },
    validate:function() {

    },
    getValue:function(isChecked) {
        var re = "",inp;
        this.wrap.getElements("div.formselect-list-item").filter(
                                                                function(row) {
                                                                    inp = row.getElements('input')[0];
                                                                    if(isChecked == false)return ($defined(inp)) ? inp.get('checked') != true : !row.hasClass("formselect-selected");
                                                                    return ($defined(inp)) ? inp.get('checked') == true : row.hasClass("formselect-selected");
                                                                }).each(function(row) {
            if(re == "")re += this.genarateContent({'code':row.get('code'),'caption':row.get('caption')});
            else re += "," + this.genarateContent({'code':row.get('code'),'caption':row.get('caption')});
        }.bind(this));
        return re;
    },
    getAllValue:function(isChecked) {
        var re = [],inp;
        this.wrap.getElements("div.formselect-list-item").filter(
                                                                function(row) {
                                                                    inp = row.getElements('input')[0];
                                                                    if(isChecked == false)return ($defined(inp)) ? inp.get('checked') != true : !row.hasClass("formselect-selected");
                                                                    return ($defined(inp)) ? inp.get('checked') == true : row.hasClass("formselect-selected");
                                                                }).each(function(row) {
            re.include({'code':row.get('code'),'caption':row.get('caption')});
        }.bind(this));
        return re;
    },
    genarateContent:function(obj) {
        var content = this.options.sbmitcontent;
        if(!$defined(content))content = "{code}";
        return content.substitute(obj);
    },
    reset:function() {
        this.wrap.getElements("div.formselect-list-item").each(function(row) {
            if(row.getElement("input"))row.getElement("input").set("checked", false);
            row.removeClass("formselect-selected");
        });
    }
    ,getChildrenEl:function() {
        return this.innerWrap.getElements('input[name=' + this.options.name + '][type=' + this.options.type + ']');
    }
    ,disable:function(FieldEl,codes) {
        this.options.disable = "true";
        var tp = this.options.type;
        if(codes&&(tp=="checkbox"||tp=="radio")){
        	var fieldAr =  codes.split(",");
        	var fel = 	this.getChildrenEl();
        	fieldAr.each(function(it){
        		fel.each(function(item){
            		if(item.get("value")==it) item.set('disabled', true);
            	});
        	});
        }else  {
        	this.getChildrenEl().set('disabled', true);
        }
    }
    ,enable:function(FieldEl,codes) {
        this.options.disable = "false";
        var tp = this.options.type;
        if(codes&&(tp=="checkbox"||tp=="radio")){
        	var fieldAr =  codes.split(",");
        	var fel = 	this.getChildrenEl();
        	fieldAr.each(function(it){
        		fel.each(function(item){
            		if(item.get("value")==it) item.set('disabled', false);
            	});
        	});
        	
        }else{
        	this.getChildrenEl().set('disabled', false);
        }
    }
    ,clearOptions:function(){
    	this.innerWrap.getElements("*").each(function(el) {
            el.destroy();
        });
    }
    ,initEvent:function() {
        this.innerWrap.addEvent("click", function(e) {
            var tar = $(new Event(e).target);
            if (tar.get("tag") == "div")return;
            var code="",caption="";
            if (tar.get("type") == "radio") {
                var oldeEl = this.innerWrap.getElement("div.formselect-selected");
                if (oldeEl) {
                	code= oldeEl.get("code");
                    caption = oldeEl.get("caption");
                }
            }else{
            	var oldeEl = this.innerWrap.getElements("div.formselect-selected");
                if (oldeEl.length>0) {
                	oldeEl.each(function(item){
                		code= code+(item.get("code")+",");
                        caption =caption+(item.get("caption")+",");
                	});
                	code=code.substring(0,code.length-1);
                	caption=caption.substring(0,caption.length-1);
                }
            }
            if ($defined(this.options.onClickBefore)) {
                this.getFunc(this.options.onClickBefore)[0](code, caption,tar);
            }
            var tarParent = tar.getParent();
            var inputEl=tarParent.getElement("input");
            if (inputEl.get("type") == "radio") {
                this.innerWrap.getElements("div.formselect-list-item").each(function(row) {
                	if (row.getElement("input")){
                    	if(!(row.getElement("input").get("disabled"))){
                    		row.getElement("input").set("checked", false);
                    		row.removeClass("formselect-selected");
                    	}
                    }else{
                    	row.removeClass("formselect-selected");
                    }
                });
                if (!$chk(inputEl.get('disabled'))){
                	tarParent.addClass('formselect-selected');
                	inputEl.set("checked", true);
                }
            } else {
            	if (tarParent.hasClass("formselect-selected")) {
                    if (!$chk(inputEl.get('disabled')))inputEl.set("checked", false);
                    tarParent.removeClass('formselect-selected');
                }
                else {
                    if (!$chk(inputEl.get('disabled')))inputEl.set("checked", true);
                    tarParent.addClass('formselect-selected');
                }
            }
            if ($defined(this.options.onClickAfter)) {
                this.getFunc(this.options.onClickAfter)[0](tarParent.get("code"), tarParent.get("caption"),tarParent);
            }
        }.bind(this));
        this.innerWrap.addEvent("keyup",function(e){
        	//e.code(9:tab,37:<,39:>,13:enter)
        	var code=e.code,el=$(e.target);
        	e.preventDefault();
        	if(code==32&&Browser.Engine.trident){el.set.delay(1,el,["checked",false]);}
        	if(code==37||code==39){
        		var divEl=el.getParent(),pEl=divEl.getParent(),cssKey="input";
        		if(el.get("type")=="checkbox"){
	        		if(code==37){
	        			var t=divEl.getPrevious()?divEl.getPrevious().getElement(cssKey):null;
	        			if(t){t.focus();}
	        			else{
	        				t=pEl.getLast().getElement(cssKey);
	        				if(t)t.focus();
	        			}
	        		}if(code==39){
	        			var t=divEl.getNext()?divEl.getNext().getElement(cssKey):null;
	        			if(t){t.focus();}
	        			else{
	        				t=pEl.getFirst().getElement(cssKey);
	        				if(t)t.focus();
	        			}
	        		}
        		}
        	}if(code==13){
        		if (!$chk(el.get('disabled'))){
        			var isC=el.get('checked');
        			if(!$chk(isC)||isC=="false"){
        				el.set("checked", true);
        			}else{
        				el.set("checked", false);
        			}
        		}
        	}
        });
        this.innerWrap.getElements("div.formselect-list-item").each(function(item){
        	item.addEvents({
        		'mouseenter':function(e){if(!item.getElement("input").get("disabled"))item.addClass("formselect-hover");},
        		'mouseleave':function(e){if(!item.getElement("input").get("disabled"))item.removeClass("formselect-hover");}
        	});
        });
    }
});


